/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import javax.swing.table.AbstractTableModel;
import main.*;
import bean.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.text.MaskFormatter;
import views.*;



public class PanelServicios extends javax.swing.JPanel implements MouseListener {
     public  int variable;
     String cad=null;
    ServicioTM miservicio = new ServicioTM();
    
   
        
    private void actualizaTabla() {
     
       miservicio.services=Main.service.queryAllServicios();
       miservicio.fireTableChanged(null);
        
    }
    
    
     private void groupButton( ) {

    ButtonGroup bg1 = new ButtonGroup( );

    bg1.add(rbtnSoles);
    bg1.add(rbtnDolares);   
    }

    @Override
    public void mouseClicked(MouseEvent e) {
//        TablaServicios.addMouseListener(this);
//        if (e.getClickCount() == 2) {
//            JTable target = (JTable)e.getSource();
//            int row = target.getSelectedRow();
//            int column = target.getSelectedColumn();
//            int idServ=Integer.parseInt(TablaServicios.getValueAt(row,0).toString());
//            int idCont=Main.principal.cont.getPanelContenedores11().getId();
//            Main.principal.ser.setVisible(false);
//            Main.service.agregaSerXcont(idServ, idCont);
//            actualizaTabla();
//         }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    class ServicioTM extends AbstractTableModel{
         
        
        	
   
          
    String titulos[]={"CODIGO","DESCRIPCION","PRECIO BASE","UNIDAD COBRO"};
      private  ArrayList<Servicio> services = Main.service.queryAllServicios();
         
        @Override
        public int getRowCount() {
           return services.size();
        }

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public Object getValueAt(int fil, int col) {//COLOCO LOS VALORES EN LA TABLA
            String res=null;
            Servicio s=services.get(fil);
            switch(col){
                case 0:
                    res = "" + s.getId();
                    break;
                case 1:
                    res = ""+s.getDescripcion();
                    break;
                case 2:
                    res = ""+s.getPreciobase();
                    break;
                                               
                case 3: 
                    res = ""+s.getUnidadcobro();
                     break;               
            }
            return res;
        }
       @Override  
        public String getColumnName(int col){
        return titulos[col];
        }
      
      }
    public PanelServicios() {
        initComponents();
        TablaServicios.setModel(miservicio);
        groupButton();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TServicio = new javax.swing.JScrollPane();
        TablaServicios = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        btnLimpiar = new javax.swing.JButton();
        btnRemove = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        txtDescripcion = new javax.swing.JTextField();
        txtPbase = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        rbtnSoles = new javax.swing.JRadioButton();
        rbtnDolares = new javax.swing.JRadioButton();
        btnBuscar = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();
        txtBuscar = new javax.swing.JTextField();
        btnAddtoCont = new javax.swing.JButton();

        TablaServicios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TablaServicios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaServiciosMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                TablaServiciosMouseEntered(evt);
            }
        });
        TServicio.setViewportView(TablaServicios);

        jLabel7.setText("Tabla de Servicios Tramarsa");

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnRemove.setText("Eliminar");
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveActionPerformed(evt);
            }
        });

        btnAdd.setText("Agregar");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        btnAdd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btnAddKeyPressed(evt);
            }
        });

        btnEdit.setText("Editar");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Datos del Servicio"));
        jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPanel1KeyReleased(evt);
            }
        });

        jLabel2.setText("Descripcion:");

        jLabel3.setText("Precio base:");

        jLabel1.setText("Id:");

        jLabel4.setText("Unidad cobro");

        txtId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdActionPerformed(evt);
            }
        });
        txtId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtIdKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtIdKeyReleased(evt);
            }
        });

        txtDescripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDescripcionActionPerformed(evt);
            }
        });
        txtDescripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtDescripcionKeyReleased(evt);
            }
        });

        txtPbase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPbaseActionPerformed(evt);
            }
        });
        txtPbase.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPbaseKeyReleased(evt);
            }
        });

        rbtnSoles.setText("Soles");
        rbtnSoles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnSolesActionPerformed(evt);
            }
        });

        rbtnDolares.setText("Dolares");
        rbtnDolares.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnDolaresActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(7, 7, 7)
                        .addComponent(jLabel6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtPbase, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                        .addComponent(txtId))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbtnSoles)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rbtnDolares)))
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtPbase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(rbtnSoles)
                            .addComponent(rbtnDolares))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnBuscar.setText("Buscar Servicio");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        btnAddtoCont.setText("Añadir a Contenedor >>");
        btnAddtoCont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddtoContActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel7)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnAdd)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEdit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnLimpiar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnRemove))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnRefresh)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBuscar)
                                .addGap(18, 18, 18)
                                .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(TServicio, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(btnAddtoCont)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnEdit)
                    .addComponent(btnLimpiar)
                    .addComponent(btnRemove))
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRefresh)
                    .addComponent(btnBuscar)
                    .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(TServicio, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAddtoCont)
                .addContainerGap(16, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        txtId.setText(null);
        txtDescripcion.setText(null);
        txtPbase.setText(null);
        //txtUnidad.setText(null);
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
        int rowSel = TablaServicios.getSelectedRow();
        String id =TablaServicios.getValueAt(rowSel,0).toString();
        Main.service.eliminaServicio(id);
        actualizaTabla();
    }//GEN-LAST:event_btnRemoveActionPerformed

  
    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
int flag=0;
        Servicio s = new Servicio();

 if( txtDescripcion.getText( ).matches( "" ) ||  txtId.getText( ).matches( "" )||txtPbase.getText( ).matches( "" ) ){
             JOptionPane.showMessageDialog(null,"Complete los campos","Error!",JOptionPane.ERROR_MESSAGE);
             flag=1;
}
                  else if (flag==0){           
                 if (variable==0){
                     s.setUnidadcobro("S");
                     s.setId(Integer.parseInt(txtId.getText()));
                     s.setDescripcion(txtDescripcion.getText());
                     s.setPreciobase(Float.parseFloat(txtPbase.getText()));}
         
                 else if (variable==1) {
                    s.setUnidadcobro("D");
                    s.setId(Integer.parseInt(txtId.getText()));
                    s.setDescripcion(txtDescripcion.getText());
                    s.setPreciobase(Float.parseFloat(txtPbase.getText()));}
      
        Main.service.agregaServicio(s);
        actualizaTabla();
             }
        
    }//GEN-LAST:event_btnAddActionPerformed
    
    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
 Servicio s = new Servicio();
        s.setId(Integer.parseInt(txtId.getText()));
        s.setDescripcion(txtDescripcion.getText());
        s.setPreciobase(Float.parseFloat(txtPbase.getText()));
        Main.service.editaServicio(s);
        actualizaTabla();
       

    }//GEN-LAST:event_btnEditActionPerformed

    private void txtIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdActionPerformed

    private void txtDescripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDescripcionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDescripcionActionPerformed

    private void txtPbaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPbaseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPbaseActionPerformed

    private void btnAddKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnAddKeyPressed
 
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnAddKeyPressed

    private void txtIdKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdKeyPressed
    }//GEN-LAST:event_txtIdKeyPressed

    private void rbtnSolesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnSolesActionPerformed
       variable=0;  
       //rbtnSoles.setVisible(true);
       
             // soles      
      
    }//GEN-LAST:event_rbtnSolesActionPerformed

    private void rbtnDolaresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnDolaresActionPerformed
        variable=1; // dolares
       
    }//GEN-LAST:event_rbtnDolaresActionPerformed

    private void txtIdKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdKeyReleased
if( ! txtId.getText( ).matches( "[0-9]*" )  ){
        JOptionPane.showMessageDialog(null,"Dato del Id no valido","Error!",JOptionPane.ERROR_MESSAGE);
 txtId.setText("");      
}  

if(txtId.getText( ).matches( "[0-9]*" )){
          String str=txtId.getText();
        int tam=str.length();
        if (tam>8) {
            JOptionPane.showMessageDialog(null,"El ID permite máximo 8 caracteres","Error!",JOptionPane.ERROR_MESSAGE); 
        txtId.setText("");
        }   
}
    }//GEN-LAST:event_txtIdKeyReleased

    private void jPanel1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel1KeyReleased

    private void txtDescripcionKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescripcionKeyReleased
if(txtDescripcion.getText( ).matches( "[a-z0-9A-Z]*" )){
        String str=txtDescripcion.getText();
        int tam=str.length();
        if (tam>50) 
        {JOptionPane.showMessageDialog(null,"La descripcion no debe exceder de 50 caracteres","Error!",JOptionPane.ERROR_MESSAGE); 
        
        }
        
}
    }//GEN-LAST:event_txtDescripcionKeyReleased
                                 
  
    
    private void txtPbaseKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPbaseKeyReleased
            
try
    { float f = Float.parseFloat( txtPbase.getText() );
      //float p_dec=f-(int)f; // OBTENGO PARTE DECIMAL
                               f=f*100;
                               float part=f-(int)f;                         
                               int aux=(int)f;
                              float p_dec=aux/100;                                            
                if (part>0 ) { //tienes mas de dos decimales {
    JOptionPane.showMessageDialog(null,"Solo se permite 2 decimales","Error!",JOptionPane.ERROR_MESSAGE); 
     txtPbase.setText("");
}
    }
catch( NumberFormatException e )
{    JOptionPane.showMessageDialog(null,"El precio base no es correcto","Error!",JOptionPane.ERROR_MESSAGE); 
     txtPbase.setText("");
   
}


    }//GEN-LAST:event_txtPbaseKeyReleased

    private void TablaServiciosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaServiciosMouseClicked
        //variable=0;
         int rowSel = TablaServicios.getSelectedRow();
        String idServicio=TablaServicios.getValueAt(rowSel,0).toString();
        String tipo=TablaServicios.getValueAt(rowSel,3).toString();
        Servicio serv=Main.service.queryByServicio(idServicio);
 
        txtId.setText(idServicio);
        txtDescripcion.setText(serv.getDescripcion());
        txtPbase.setText(Float.toString(serv.getPreciobase()));
        //REVISAR  
            if (tipo.equals("S"))  {
        rbtnSoles.setSelected(true);
        rbtnDolares.setSelected(false);
          }
           else if(tipo.equals("D"))   {        
                rbtnDolares.setSelected(true);   
                rbtnSoles.setSelected(false);
           }
            
         
    }//GEN-LAST:event_TablaServiciosMouseClicked

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        ArrayList<Servicio> result=Main.service.queryAllServicios();
        ActualizarBusqueda(result);
        txtBuscar.setText(""); // TODO add your handling code here:
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
        cad=txtBuscar.getText();
        ArrayList<Servicio> result=Main.service.queryByNS(cad);
        ActualizarBusqueda(result);
        
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void TablaServiciosMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaServiciosMouseEntered
//        int idServ=Integer.parseInt(txtId.getText());
//        int idCont=Main.principal.cont.getPanelContenedores11().getId();
//        Main.principal.ser.setVisible(false);
//        Main.service.agregaSerXcont(idServ, idCont);
//        actualizaTabla();
    }//GEN-LAST:event_TablaServiciosMouseEntered

    private void btnAddtoContActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddtoContActionPerformed
        int idServ=Integer.parseInt(txtId.getText());
        int idCont=Main.principal.cont.getPanelContenedores11().getId();
        Main.principal.ser.setVisible(false);
        Main.service.agregaSerXcont(idServ, idCont);
        main.Main.principal.cont.getPanelContenedores11().actualizaTabla2();
        
    }//GEN-LAST:event_btnAddtoContActionPerformed

    
    
  public void ActualizarBusqueda(ArrayList<Servicio> s){
        miservicio.services=s;
        miservicio.fireTableChanged(null);
    }

  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane TServicio;
    private javax.swing.JTable TablaServicios;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnAddtoCont;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnRemove;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton rbtnDolares;
    private javax.swing.JRadioButton rbtnSoles;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtPbase;
    // End of variables declaration//GEN-END:variables
}
